<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8" />
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <title>Document</title>
    </head>
    <body>
        <script>
            /* 可以循环遍历，很简单，拼接下数组即可 */
            var nextGreaterElements = function (nums) {
                let result = new Array(nums.length).fill(-1)
                let arr = [...nums, ...nums]
                for (let i = 0; i < nums.length; i++) {
                    for (let j = i + 1; j < arr.length; j++) {
                        if (arr[j] > arr[i]) {
                            result[i] = arr[j]
                            break
                        }
                    }
                }
                return result
            }
            console.log(nextGreaterElements([1, 2, 3, 4, 3]))
        </script>
    </body>
</html>
